//
//  WebViewController.m
//  News_lzz
//
//  Created by qianfeng01 on 15-6-14.
//  Copyright (c) 2015年 李忠. All rights reserved.
//

#import "WebViewController.h"

@interface WebViewController () <UIWebViewDelegate>
@property (strong, nonatomic) UIWebView *webView;
@end

@implementation WebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createWebView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)createWebView {
    self.webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.url]];
    [self.webView loadRequest:request];
    self.webView.delegate = self;
    [self.view addSubview:self.webView];
    [self createButtonItems];
}

- (void)createButtonItems {
    UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFastForward target:self action:@selector(itemWebClick:)];
    item1.tag = 1001;
    UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(itemWebClick:)];
    item1.tag = 1002;
    UIBarButtonItem *item3 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRewind target:self action:@selector(itemWebClick:)];
    item1.tag = 1003;
    UIBarButtonItem *item4 = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"navigationbar_back_icon"] style:UIBarButtonItemStyleDone target:self action:@selector(itemWebClick:)];
    item4.tag = 1004;
    self.navigationItem.leftBarButtonItem = item4;
    self.navigationItem.rightBarButtonItems = @[item1,item2,item3];
}

- (void)itemWebClick:(UIBarButtonItem *)item {
    switch (item.tag) {
        case 1001:
        {
            [self.webView goForward];
        }
            break;
        case 1002:
        {
            [self.webView reload];
        }
            break;
        case 1003:
        {
            [self.webView goBack];
        }
        case 1004:
        {
            [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
            [self.navigationController popViewControllerAnimated:YES];
        }
            break;
        default:
            break;
    }
}

#pragma mark - UIWebView 协议方法

- (void)webViewDidStartLoad:(UIWebView *)webView {
    NSLog(@"已经开始加载");
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; //打开菊花
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    NSLog(@"已经加载完成");
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}



@end
